/*
 Copyright (c) 2013 MeherTJ G. All rights reserved.
 License: LGPL for personnal study or free software.
 */

#pragma once

#include "zen_app.h"

#if ZEN_OS_OSX

#import "AppMetalViewController.h"
#import "AppMetalRenderer.h"

class AppMac : public Zen::App
{
protected:
	std::shared_ptr<Zen::AppDelegate> m_delegate = nullptr;
	
	Zen::P2i mSize;
	
	bool m_rotatable = false;
	
	bool m_status_visible = false;
	
	bool m_is_paused = false;
	
	bool m_is_bg_render = false;

	static std::shared_ptr<AppMac> _me;
	
public:
	static std::shared_ptr<AppMac> Instance()
	{
		return _me;
	}
	
	virtual void SetRuntimeDelegate
	(std::shared_ptr<Zen::AppDelegate> delegate)
	override
	{
		m_delegate = delegate;
	}
	
	virtual void OnUpdate()
	{
		
	}
	virtual void OnDraw()
	{
		
	}
	
	virtual std::shared_ptr<Zen::AppDelegate>
	GetRuntimeDelegate() override
	{
		return m_delegate;
	}
	
	virtual float GetFramesPerSecond() override
	{
		return [gViewController GetFPS];
	}
	virtual void SetFramesPerSecond(float frames) override
	{
		[gViewController SetFPS:(int)frames];
	}
	
	virtual bool IsMultiTouchEnabled() override
	{
		return false;
	}
	virtual void SetMultiTouchEnabled(bool use) override
	{
	}
	
	virtual bool IsRotatable() override
	{
		return m_rotatable;
	}
	virtual void SetRotatable(bool r) override
	{
		m_rotatable = r;
	}
	
	virtual bool IsStatusVisible() override
	{
		return m_status_visible;
	}
	virtual void SetStatusVisible(bool show) override
	{
		m_status_visible = show;
	}
	
	virtual bool IsBGUpdate() override
	{
		return m_is_bg_render;
	}
	
	virtual void SetBGUpdate(bool v) override
	{
		m_is_bg_render = v;
	}

public:
	void Update();
	
	void draw();
	
	void launch(Zen::P2i view_size);
	
	void resize(Zen::P2i view_size);
	
	void exit();
	
	void pause();
	
	void resume();
	
	void touchDown(Zen::AppTouch);
	
	void touchUp(Zen::AppTouch);
	
	void touchCancel(Zen::AppTouch);
	
	void touchMove(Zen::AppTouch);
	
protected:
	AppMac()
	{
		m_delegate = nullptr;
	}
};

#endif
